package cn.sdstudio.controller;

import cn.sdstudio.model.PageResult;
import cn.sdstudio.model.Result;
import cn.sdstudio.dto.TravelGuideDTO;
import cn.sdstudio.vo.TravelGuideVO;
import cn.sdstudio.service.TravelGuideService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/guide")
@RequiredArgsConstructor
@Tag(name = "旅游攻略")
public class TravelGuideController {

    private final TravelGuideService travelGuideService;

    @PostMapping("/create")
    @Operation(summary = "创建旅游攻略")
    public Result<Long> createGuide(@RequestBody TravelGuideDTO travelGuideDTO) {
        Long guideId = travelGuideService.createGuide(travelGuideDTO);
        return Result.success(guideId);
    }

    @GetMapping("/{id}")
    @Operation(summary = "获取攻略详情")
    public Result<TravelGuideVO> getGuideById(@PathVariable Long id) {
        TravelGuideVO guide = travelGuideService.getTravelGuideVoById(id);
        return Result.success(guide);
    }

    @GetMapping("/list")
    @Operation(summary = "分页查询攻略列表")
    public Result<PageResult<TravelGuideVO>> listGuides(
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResult<TravelGuideVO> result = travelGuideService.listGuides(pageNo, pageSize);
        return Result.success(result);
    }

    @GetMapping("/by-scenic/{scenicId}")
    @Operation(summary = "根据景点ID查询相关攻略")
    public Result<List<TravelGuideVO>> getGuidesByScenicId(@PathVariable Long scenicId) {
        List<TravelGuideVO> guides = travelGuideService.getGuideScenicRelations(scenicId);
        return Result.success(guides);
    }
}
